package com.quanyan.stadium.web.admin;

import com.quanyan.api.APIResponse;
import com.quanyan.stadium.api.req.admin.ReqFoundOrder;
import com.quanyan.stadium.api.req.admin.ReqOrderList;
import com.quanyan.stadium.entity.TbGameEvent;
import com.quanyan.stadium.entity.TbGameOrder;
import com.quanyan.stadium.service.admin.AdminGameEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 * User: zyq
 * Date: 2016/8/1 0001
 * Time: 17:36
 */

@RestController
@RequestMapping("/admin/api/stadium/gameOrder")
public class OrderController {

    @Autowired
    AdminGameEventService gameEventService;

    /**
     * 分页查询订单列表
     * @param order
     * @param result
     * @param
     * @return
     */
    @RequestMapping(value="/queryOrderList", method = RequestMethod.POST)
    public APIResponse<?> createIntegrateGame(@RequestBody @Valid ReqOrderList order, BindingResult result)  {
        if (result.hasErrors()) {
            return APIResponse.returnFail(result.getFieldError().getDefaultMessage());
        }
        return gameEventService.queryOrderList(order);
    }

    /**
     * 查询订单详情
     * @param order
     * @param result
     * @param
     * @return
     */
    @RequestMapping(value="/queryOrderDetail", method = RequestMethod.POST)
    public APIResponse<?> queryOrderDetail(@RequestBody @Valid TbGameOrder order, BindingResult result)  {
        if (result.hasErrors()) {
            return APIResponse.returnFail(result.getFieldError().getDefaultMessage());
        }
        return gameEventService.queryOrderDetail(order);
    }


    /**
     * 查询赛事详情
     * @param event
     * @param result
     * @param
     * @return
     */
    @RequestMapping(value="/queryGameEvent", method = RequestMethod.POST)
    public APIResponse<?> queryGameEvent(@RequestBody @Valid TbGameEvent event, BindingResult result)  {
        if (result.hasErrors()) {
            return APIResponse.returnFail(result.getFieldError().getDefaultMessage());
        }
        return gameEventService.queryGameEvent(event);
    }


    @RequestMapping(value="/refoundOrder", method = RequestMethod.POST)
    public APIResponse<?> refoundOrder(@RequestBody @Valid ReqFoundOrder request, BindingResult result)  {
        if (result.hasErrors()) {
            return APIResponse.returnFail(result.getFieldError().getDefaultMessage());
        }
        return gameEventService.refound(request);
    }


}
